package com.beerandjesus.blackjack.deck;

import java.util.List;
import java.util.Iterator;

/**
 * User: reverend
 * Date: Feb 10, 2007
 * Time: 2:02:26 AM
 */
public class CardCounter {
    public static int count(List hand) {
        int aceCount = 0;
        int handCount = 0;
        Iterator it = hand.iterator();
        while (it.hasNext()) {
            Card card = (Card) it.next();
            if (card.isAce()) {
                aceCount++;
            } else {
                handCount += card.getValue();
            }
        }
        if (aceCount > 0) {
            for (int i = 0; i < aceCount; i++) {
                if (handCount + 11 <= 21) {
                    handCount += 11;
                } else {
                    handCount += 1;
                }
            }
        }
        return handCount;
    }
}
